<template>
  <div class="heart">
    <Aside></Aside>
    <Header :title="title" @toggleMenu="toggleMenu" @navToBack="navToBack"></Header>
    <div class="heartBanner">
      <img src="https://api.cloudcpc.com/static/index//images/heart.jpg" alt="">
    </div>
    <div class="haertContent">
      <div class="heartItem">
        <div class="heartInner">
          <div class="heartList" v-for="(item,index) in heartList" >
            <img :src=item.take alt="">
            <div class="heartRight">
              <p class="name">{{item.username}}</p>
              <p class="joinTime">{{item.ctime}}</p>
              <p class="position">
               {{item.company_name}} {{item.department}}
              </p>
              <p class="motto">
                {{item.title}}
              </p>
            </div>
          </div>
        </div>
        <div class="newspage" v-if="noData">
          <router-link :to="{path:'heart',query:{p:'prev'}}">
                <span   >
                  <<上一页
               </span>
          </router-link>
          <router-link :to="{path:'heart',query:{p:'next'}}" >
            <span >下一页>></span>
          </router-link>
        </div>
        <div class="noData" v-if="!noData">
          <img src="https://api.cloudcpc.com/static/index/images/noData.png" alt="">
        </div>
      </div>
      <div class="heartBtn">
        <!--<router-link :to="{path:'/contribute'}">-->
          <span @click.stop="contribute">我要投稿</span>
        <!--</router-link>-->
      </div>
    </div>
    <div class="tips" v-if="tips">
      <span>{{tipsHtml}}</span>
    </div>
  </div>
</template>
<script >
  import aside from '../../components/aside.vue'
  import header from '../../components/header.vue'
  import {mapState} from 'vuex'
  export default({
    data (){
      return {
        title:'一颗红心',
        defaultIndex:0,
        defaultPage:1,
        heartList:[],
        maxLength:5,
        tips:false,
        tipsHtml:'',
        noData:false
      }
    },
    components:{
      Aside:aside,
      Header:header
    },
    computed:{
      ...mapState({
        uid:state =>state.app.loginState.uid ||localStorage.getItem('uid'),
        token:state=>state.app.loginState.token ||localStorage.getItem('token'),
      })
    },
    methods:{
      contribute(){
          if(this.uid&&this.token){
            this.$router.push({
              path:'/contribute'
            })
          }else{
            this.tips =true
            this.tipsHtml='请先登录后再进行该操作！'
            setTimeout(()=>{
              this.tips=false
            },1500)
          }
      },
      prev(){
        this.defaultPage--
      },
      next(){
      this.defaultPage++
      },
      navToBack(){
        this.$router.go(-1);//返回上一层
      },
      choiseffclTab (index){
        this.defaultIndex =index
      },
      toggleMenu(){
        $('.aside').toggleClass('active')
        $('body').toggleClass('active')
        if($('.aside').hasClass('active')){
          $('#toggleBtn').find('.img2').hide()
          $('#toggleBtn').find('.img1').show()
        }else{
          $('#toggleBtn').find('.img1').hide()
          $('#toggleBtn').find('.img2').show()
        }
      },
      loadMore (){
        this.loadmoreClick =!this.loadmoreClick
      },
      choiseHead(index){
        this.defaultIndex =index
      },
      initData(p){
        this.heartList =[]
        if(this.uid&&this.token){
          this.axios.post('/home/Heart/getHeartList?'+`${this.baseUrl}`,{
            p:p,
            uid:this.uid
          })
            .then((res)=>{
              console.log(res)
              this.maxLength =res.data.data.sum
              if(this.maxLength>0){
                this.noData =true
              }
              this.heartList.push(...res.data.data.data)
            })
            .catch((err)=>{
              console.log(err)
            })
        }
      }
    },
    mounted (){
      $('body').removeClass('active')
      var clientWidth =document.documentElement.clientWidth
      this.initData(this.defaultPage)
    },
    beforeRouteUpdate(to,from,next){
        if(to.query.p=='prev'){
          this.defaultPage--
          if(this.defaultPage<=0){
            this.defaultPage =0
              this.tips =true
              this.tipsHtml='没有上一页了！'
              setTimeout(()=>{
                    this.tips=false
              },1500)
              return false
          }else{
            this.initData(this.defaultPage)
          }
        }else if(to.query.p=='next'){
          this.defaultPage++
          if(this.defaultPage>=this.maxLength){
            this.defaultPage =this.maxLength
            this.tips =true
            this.tipsHtml='没有下一页了！'
            setTimeout(()=>{
              this.tips=false
            },1500)
              return false
          }else{
            this.initData(this.defaultPage)
          }
        }
    },
  })
</script>
<style scoped>
  .heart{
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
.newspage{
  font-size:0;
  margin-top: 0.2rem;
}
.newspage span{
  display: inline-block;
  width: 50%;
  height: 40px;
  line-height: 40px;
  font-size:0.24rem;
  color: #a06801;
  text-align: center;
}
.newspage span.dsisabled{
  color: #ccc;
}
  .heartBanner{
    height: 3.6rem;
    position: relative;
  }
  .haertContent{
    background: #f3debc;
    padding:  0 0.32rem;
    padding-top: 0.16rem;
    height: calc(100% - 3.6rem);
  }
  .haertContent img{
  }
  .heartItem{
    height: calc( 100% - 1.4rem );
    overflow-y: scroll;
    /*background-image: url("../../../static/images/haertBg2.png");*/
    /*background-size: 6.88rem 18.09rem;*/
    /*background-repeat: no-repeat;*/
    /*height: 18.09rem;*/
    /*overflow: hidden;*/
  }
  .heartInner{
    padding: 0 0.25rem;
    /*margin-top: 0.78rem;*/
  }
  .heartList{
    height: 2.6rem;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    border: 0.01rem dashed #dab66a;
    background: #fffdfa;
    vertical-align: top;
    padding: 0.2rem;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    margin-top: 0.2rem;
  }
  .heartList img{
    width: 2.44rem;
    height: 2.19rem;
    border: 0.01rem dashed #dab66a;
    margin-right: 0.18rem;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
  }
  .heartList .heartRight{
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    min-width: 0;
    color: #a06801;
  }
  .heartRight .name{
    font-size: 0.32rem;
  }
  .heartRight .joinTime{
    font-size: 0.24rem;
    /* padding-bottom: 0.14rem; */
    /* padding-top: 0.07rem; */
  }
  .position{
    font-size: 0.26rem;
    line-height: 1.5;
  }
  .motto{
    color: #e83329;
    font-weight: bold;
    font-size: 0.3rem;
  }
  .heartBtn,.sendBtn{
    text-align: center;
    /*padding-bottom: 0.79rem;*/
  }
  .heartBtn span,.sendBtn span{
    display: inline-block;
    font-size: 0.32rem;
    color: white;
    width: 4.5rem;
    height: 0.7rem;
    text-align: center;
    line-height: 0.7rem;
    background: #e83329;
    border-radius: 0.32rem;
    -webkit-border-radius: 0.32rem;
  }
  .heartForm{
    padding: 0.47rem 0.32rem 0.76rem 0.32rem;
  }
  .formItem{
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    /*-webkit-box-align: center;*/
    /*-webkit-align-items: center;*/
    /*align-items: center;*/
  }
  .formItem label{
    width: 1.68rem;
    height: 0.7rem;
    vertical-align: middle;
    line-height: 0.7rem;
  }
  .formItem .heartSelect,.heartInput{
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    min-width: 0;
    height: 0.7rem;
    padding-left: 0.83rem;
  }

  .heartTextArea{
    height: 4rem;
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    min-width: 0;
    -webkit-appearance: none;
    apperance:none;
    cursor: pointer;
    border-radius: 0.08rem;
    border: 1px solid #e6e6e6;
  }
  .heartSelect,.heartInput{
    border: 1px solid #e6e6e6;
    border-radius: 0.08rem;
    position: relative;
    margin-bottom: 0.2rem;

  }
  .heartInput{
    padding-right: 0;
  }
  .heartInput input{
    display: inline-block;
    width: 100%;
    height:0.66rem;
    -webkit-appearance: none;
    border: none;
    outline: none;
  }
  .heartSelect:after{
    content: " ";
    display: inline-block;
    border-width: 6px 6px 0 6px;
    border-color:#C8C8CD transparent transparent transparent ;
    border-style: solid;
    position: relative;
    top: -2px;
    position: absolute;
    top: 50%;
    right: 15px;
    margin-top: -4px;
  }
  .formItem .heartSelect select{
    -webkit-appearance: none;
    border: 0;
    outline: 0;
    background-color: transparent;
    width: 100%;
    font-size: inherit;
    height: 100%;
    line-height: 0.7rem;
    position: relative;
    z-index: 1;
    text-align: right;
    color:#C8C8CD ;
  }
  /*select {*/
  /*direction: rtl;*/
  /*}*/
  /*select option {*/
  /*direction: ltr;*/
  /*}*/
  .heartTextArea textarea{
    display: inline-block;
    width: 100%;
    height: 100%;
    -webkit-appearance: none;
    border: 0;
    outline: 0;
    background-color: transparent;
  }
.noData{
  text-align: center;
  width: 100%;
  height: 100%;
}
.noData img{
  position: absolute;
  left: 0;
  top:0;
  bottom: 0;
  right: 0;
  margin: auto;
}
</style>
